package com.Enumeration枚举类;

/**
 * 作    者 ：吾路巴尼
 * 创建时间 ：2025-02-12:50
 * 演示enum继承父类 Enum的常用方法
 */
public class Enum常用方法 {
    public static void main(String[] args) {
        Season03 d = Season03.SPRING;
        System.out.println(d.name());     // 1.对象.name() 返回枚举常量名
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

        System.out.println(d.ordinal());  // 2.对象.ordinal() 返回枚举常量在枚举类中的索引，从0开始,因为SPRING在0，所以输出0
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

        Season03[] values = Season03.values();  // 3.枚举类/对象.values() 返回枚举类中的所有枚举对象，返回值类型为数组。注意values（）方法是隐藏；
        for (int i = 0; i < values.length; i++) {  // 遍历枚举类中的枚举对象数组
            System.out.println("Season03的第" + i + "个   " + values[i]);
        }
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

        Season03 aa = Season03.valueOf("SPRING");// 4.枚举类.valueOf(String name) 返回枚举类中指定名称的枚举常量，如果找不到，则抛出异常。
        System.out.println(aa == d);//第一行的d和aa是同一个对象，所以输出true
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

        System.out.println(Season03.WINTER.compareTo(Season03.SUMMER));
        //WINTER索引在枚举类中的索引为3，SUMMER索引在枚举类中的索引为1，所以返回2
        // 5.枚举对象1.compareTo(枚举对象2) 比较两个枚举对象在枚举类中的索引，返回枚举对象1的 索引 - 枚举对象2 索引的差值，如果相等则返回0

    }
}


enum Season03 {
    SPRING("春天","春暖花开"),SUMMER("夏天","夏日炎炎"),
    AUTUMN("秋天","秋高气爽"),WINTER("冬天","冰天雪地");
    private String name;
    private String desc;
    private Season03(String name,String desc) {
        this.name = name;
        this.desc = desc;
    }
    public String toString() {
        return "Season02{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }

}